<script>
function disp_del(id) {
   if(id=='-1') {
      alert('Error: Note not found');
      return;
      }
   var el=$('item_'+id);
   new Effect.BlindUp(el);
   }
function del(id) {
   if (confirm('Delete this note ?')) {
      var el = $('de'+id);
      el.src = '/images/loading.gif';
      new Ajax.Request('/notes/delete/'+id, {asynchronous:true, evalScripts:true, onComplete:function(request){disp_del(request.responseText)}});
      }
   return false;
   }
</script>   
<%= @notes.size %> notes for this task.<br />

<% form_tag('/notes/create') do -%>
<%= text_area('new', 'content', {'cols' => 70, 'rows' => 10}) %><br />
<%= hidden_field_tag('task_id',params['id']) -%>
<%= submit_tag('Add note',{:class => 'button'}) -%>
<% end -%>

<% for n in @notes
   u = n.user
-%>

<div id="item_<%=n.id%>" class="note">
<div class="header">
Written <b><%= time_ago_in_words(n.created_on) %> ago</b> by <% if u!= nil then %><%= u.name %><%end%>
<%= link_to(image_tag('edit.gif'),:action=>:edit, :id=>n) %>
<a href="#" onclick="del(<%=n.id%>);return false;"><img id="de<%=n.id%>" src="/images/delete.gif" border="0"></a>
<br/>
<% if n.created_on != n.updated_on -%>
Updated <b><%= time_ago_in_words(n.updated_on) %></b> by <%= User.find(n.updated_by).name %><br />
<% end -%>
</div>
<div class="content">
<%= simple_format n.content %>
</div>
</div>

<% end -%>
